/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Exercicio3;

/**
 *
 * @author Pedro-Note
 */
public class Quad {
   private double EPS = 0.000000000001;
   Quad(){

    }

    public double quad(double left, double right, double fleft, double fright, double lrarea)
    {
        double mid = (left + right) / 2;
        double fmid = Math.floor(mid);
        double larea = (fleft + fmid) * (mid - left) / 2;
        double rarea = (fmid + fright) * (right - mid) / 2;
        if (Math.abs((larea + rarea) - lrarea) >  EPS) {
            larea = quad(left, mid, fleft, fmid, larea);
            rarea = quad(mid, right, fmid, fright, rarea);
        }
        return (larea + rarea);
    }

}
